//
//  TravelTourImageViewCollectionViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/24.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelTourImageViewCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import <SDWebImageManager.h>



@interface TravelTourImageViewCollectionViewCell ()

@property (nonatomic, retain) UIImageView *imagePic;

@property (nonatomic, retain) UILabel *labelDes;
@end

@implementation TravelTourImageViewCollectionViewCell

-(void)dealloc
{
    [_model release];
    [_imagePic release];
    [_labelDes release];
    [super dealloc];
    
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imagePic = [[UIImageView alloc]init];
        self.imagePic.center = self.center;
        [self addSubview:self.imagePic];
        self.imagePic.backgroundColor = [UIColor purpleColor];
        [_imagePic release];
        
        self.labelDes =[[ UILabel alloc]init];
        self.labelDes.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3];
        self.labelDes.textColor = [UIColor whiteColor];
        self.labelDes.font = [UIFont systemFontOfSize:14 *kWidth];
        [self.imagePic addSubview:self.labelDes];
        [_labelDes release];
        
    }
    
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    
   

}




-(void)setModel:(TravelTourSmallModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
  
    [self.imagePic sd_setImageWithURL:[NSURL URLWithString:model.photo_url] placeholderImage:[UIImage imageNamed:@"Travel_place"]];
    
    if (model.Des.length != 0) {
        self.labelDes.text = model.Des;
    }
    CGFloat wd = [self.model.width floatValue];
    CGFloat ht = [self.model.height floatValue];
    
    CGFloat y = (int)ht/wd *375 *kWidth;
    
    self.imagePic.frame = CGRectMake(0, 0, 370*kWidth, y);
    
      self.imagePic.center = CGPointMake(375 / 2 *kWidth, 637  / 2 *kHeight);
    if (self.model.Des.length !=0 ) {
        
        self.labelDes.frame = CGRectMake(0, self.imagePic.frame.size.height / 8 *7, self.imagePic.frame.size.width, self.imagePic.frame.size.height / 8);
    }else{
        self.labelDes.frame = CGRectMake(0, 0, 0, 0);
    }
  
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
